﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KBC_Quiz_Show.Object;
using KBC_Quiz_Show.Bussiness;
using KBC_Quiz_Show.Presentation;

namespace KBC_Quiz_Show
{
    public partial class FrmRegister : DevComponents.DotNetBar.Office2007RibbonForm
    {
        Player p;
        PlayerBus pb;

        public FrmRegister()
        {
            InitializeComponent();
            pb = new PlayerBus();
        }

        public bool IsNumber(string value)
        {
            foreach (Char c in value)
            {
                if (!Char.IsDigit(c))
                    return false;
            }
            return true;
        }

        public bool checkValue()
        {
            if (txtName.Text.ToString().CompareTo("") == 0)
            {
                MessageBox.Show("Name is not null");
                return false;
            }
            else if(txtAge.Text.ToString().CompareTo("") == 0)
            {
                MessageBox.Show("Age is not null");
                return false;
            }
            else if(!IsNumber(txtAge.Text))
            {
                MessageBox.Show("Age must is number!");
                return false;
            }
            else if(!rdFemale.Checked && !rdMale.Checked)
            {
                MessageBox.Show("Must choice gender!");
                return false;
            }
            else if (txtAddress.Text.ToString().CompareTo("") == 0)
            {
                MessageBox.Show("Address is not null");
                return false;
            }
            else
            {
                return true;
            }
        }

        private void FrmRegister_Load(object sender, EventArgs e)
        {
            rdMale.Checked = true;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (this.checkValue() == true)
            {
                string name = txtName.Text;
                int age = Int32.Parse(txtAge.Text.ToString());
                string address = txtAddress.Text;
                int gender = 1;
                if (rdMale.Checked)
                {
                    gender = 1;
                }
                else if (rdFemale.Checked)
                    gender = 0;
                p = new Player(name, address, gender, age);
                FrmGame game = new FrmGame();
                game.setPlayer(p);
                //game.Visible = true;
                game.Show();
            }
        }
    }
}
